package com.foreknow.mapping;

import java.util.HashMap;
import java.util.Map;

/**
 * 工厂类：主要的作用是用来管理xxxMapping的
 */
public class MappingFactory {

    private static MappingFactory mappingFactory = null;
    private Map<String,EntityMapping> maps = new HashMap<>();
    public static final String ADMIN_MAPPING = "adminMapping";
    public static final String GUESTBOOK_MAPPING = "guestbookMapping";
    //public static final String XXX_MAPPING = "xxxMapping";
    private MappingFactory(){

    }
    public static MappingFactory getInstance() {
        if(mappingFactory==null){
            mappingFactory = new MappingFactory();
            //向Map集合中保存xxxMapping对象
            mappingFactory.maps.put(ADMIN_MAPPING,new AdminMapping());
            mappingFactory.maps.put(GUESTBOOK_MAPPING,new GuestbookMapping());
            //mappingFactory.maps.put(XXX_MAPPING,new AdminMapping());
        }
        return mappingFactory;
    }
    /**
     * 从Map集合中根据key获取到xxxMapping对象
     * 因为这些xxxMapping对象都实现了EntityMapping接口
     * @param key
     * @return EntityMapping(接口、父类型) 多态
     */
    public EntityMapping getMap(String key) {
        return maps.get(key);
    }
}
